package Controller.Actions.Modify;

import Controller.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import Model.Beans.Results.*;
import Model.Beans.*;
import Model.QBE.*;

public class ModifyClassroomAction implements Action {
    
    private String name;
    
    public ModifyClassroomAction() 
    {
        this.name = "ModifyClassroom";
    }
    
    public String getName()
    {
        return name;
    }
   
    public void perform(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        ClassroomModel cmodel = new ClassroomModel();
        String id = request.getParameter("id");
        String building = request.getParameter("building");
        String number = request.getParameter("number");
        
        ClassRoom classroom = new ClassRoom(Integer.parseInt(id), building, Integer.parseInt(number));
        
        if(cmodel.modify(classroom) != 0)
        {
            response.getWriter().write("<message> The classroom " + classroom.toString() +  " has been successfully modified </message>");
        }
        else
        {
            response.getWriter().write("<message>The classroom doesn't exists</message>");
        }
    }
}
